package com.yjq.blog.user.service.impl;

import com.yjq.blog.user.entity.User;
import com.yjq.blog.user.repository.UserRepository;
import com.yjq.blog.user.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserRepository userRepository;

    @Override
    public User getUserById(Integer id) {
        return userRepository.findById(id).orElse(new User());
    }

    @Override
    public Map<Integer, User> getUserMapByIdList(List<Integer> idList) {
        List<User> userList = userRepository.findAllById(idList);
        return userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));
    }

}
